package com.qf.springbootopenapi.controller;

import com.qf.springbootopenapi.annotation.NullValidation;
import com.qf.springbootopenapi.service.UserService;
import com.qf.springbootopenapi.vo.HelloVo;
import com.qf.springbootopenapi.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;


@RestController
@RequestMapping("/hello")
public class HelloController {
    
    @Qualifier("userBetterServiceImpl")
    @Autowired
    private UserService userService;
    
    @GetMapping("/test1")
    public String test1(){
        return "hello ssm";
    }
    
    
    @GetMapping("/test2")
    public ResultVo test2(@Valid HelloVo helloVo){ //使用@Valid参数校验功能
        System.out.println(helloVo);
        
        return new ResultVo(1, "ok");
    }
    
    @PostMapping("/test3")
    public ResultVo test3(@RequestBody @Valid HelloVo helloVo){ //使用@Valid参数校验功能
        System.out.println(helloVo);
        
        return new ResultVo(1, "ok");
    }
    
    @GetMapping("/test4")
    @NullValidation
    public ResultVo test4(String name, Integer id){ //使用@Valid参数校验功能
        System.out.println(name);
        
        System.out.println(id);
        
        return new ResultVo(1, "ok");
    }
    
}
